package net.wanho.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import net.wanho.entity.User;
import net.wanho.service.UserService;
import net.wanho.service.impl.UserServiceImpl;
import net.wanho.vo.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * Author：汤小洋
 * Date：2024-12-11 16:22
 * Description：<描述>
 */
// @Controller
// @ResponseBody
@RestController // @Controller + @ResponseBody
@RequiredArgsConstructor
@Api(tags = "01.用户模块")
public class UserController {

    // @Autowired
    // @Resource
    private final UserService userService;

    // @Autowired
    // public void setUserService(UserService userService) {
    //     this.userService = userService;
    // }


    @ApiOperation("用户注册")
    @GetMapping("/register")
    // @ResponseBody
    public String register(@ApiParam("用户名") String username,@ApiParam("密码") String password){
        userService.register(username, password);
        return "注册成功";
    }

    @ApiOperation("注销退出")
    @GetMapping("/logout")
    // @ResponseBody
    public String logout(){
        return userService.logout();
    }

    @ApiOperation("用户登录")
    @GetMapping("/login")
    public User login(String username, String password){
        User user = new User(1001, username, password, null, LocalDateTime.now());
        return user;
    }

    @ApiOperation("用户列表")
    @GetMapping("/findAllUsers")
    public AjaxResult findAllUsers(){
        List<User> list = userService.findAll();
        return AjaxResult.success(list);
    }
}
